package com.iworkh.spring.data.jdbc.tx;

import com.iworkh.spring.data.jdbc.tx.dao.BookDao;
import com.iworkh.spring.data.jdbc.tx.dao.StudentDao;
import com.iworkh.spring.data.jdbc.tx.service.OrderService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * 入口类
 *
 * @author: iworkh-沐雨云楼
 * @date: 2019-12-20
 */
public class App {
    public static void main(String[] args) {

        ApplicationContext context = new ClassPathXmlApplicationContext("spring-jdbc-tx.xml");
        BookDao bookDao = (BookDao) context.getBean("bookDao");
        StudentDao studentDao = (StudentDao) context.getBean("studentDao");

        System.out.println("book count before: " + bookDao.getCount("1"));
        System.out.println("student money before: " + studentDao.getMoney("1"));

        OrderService orderService = (OrderService) context.getBean("orderService");
        orderService.makeAnOrder("1", "1", 60);

        System.out.println("book count after: " + bookDao.getCount("1"));
        System.out.println("student money after: " + studentDao.getMoney("1"));

        System.out.println("end...");
    }
}
